<%@Page Language="VB"%>

<%@Import Namespace="System.Data" %>
<%@Import Namespace="System.Data.OleDb" %>

<%@Import Namespace="System.Data.Common" %>

<%@ Register TagPrefix="wrox" TagName="connect" Src="..\global\connect-strings.ascx" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head>
<title>Returning XML from a DataSet</title>
<!-- #include file="..\global\style.inc" -->
</head>
<body bgcolor="#ffffff">
<span class="heading">Returning XML from a DataSet</span><hr />
<!--------------------------------------------------------------------------->

<%'-- insert connection string script --%>
<wrox:connect id="ctlConnectStrings" runat="server" />

<div>Connection string: <b><span id="outConnect" runat="server"></span></b></div>
<div>SELECT command: <b><span id="outSelect" runat="server"></span></b></div>
<div id="outError" runat="server">&nbsp;</div>

<form id="frmThis" runat="server">
<input type="checkbox" id="chkXML" onclick="frmThis.submit()" runat="server" /> Display XML Data &nbsp;
<input type="checkbox" id="chkSchema" onclick="frmThis.submit()" runat="server" /> Display XML Schema &nbsp;
</form>

<%'-- create XMP element to display the XML document --%>
<xmp id="xmpResults" runat="server" /></xmp>

<script language="VB" runat="server">

Sub Page_Load()
   ShowData()
End Sub

Sub ShowData

   'get connection string from ..\global\connect-strings.ascx user control
   Dim strConnect = ctlConnectStrings.OLEDBConnectionString
   outConnect.innerText = strConnect 'and display it

   'specify the SELECT statement to extract the data
   Dim strSelect As String
   strSelect = "SELECT BookList.*, BookAuthors.FirstName, BookAuthors.LastName " _
             & "FROM BookList INNER JOIN BookAuthors ON BookList.ISBN = BookAuthors.ISBN " _
             & "WHERE BookList.ISBN LIKE '18610033%'"
   outSelect.innerText = strSelect   'and display it

   'create a new DataSet object
   Dim objDataSet As New DataSet()

   Try

      'create a new Connection object using the connection string
      Dim objConnect As New OleDbConnection(strConnect)

      'create a new DataAdapter using the connection object and select statement
      Dim objDataAdapter As New OleDbDataAdapter(strSelect, objConnect)

      'fill the dataset with data from the DataAdapter object
      objDataAdapter.Fill(objDataSet, "Books")

   Catch objError As Exception

      'display error details
      outError.innerHTML = "<b>* Error while accesing data</b>.<br />" _
          & objError.Message & "<br />" & objError.Source
      Exit Sub  ' and stop execution

   End Try

   'display the data and/or schema in the DataSet as an XML document
   xmpResults.InnerHtml = ""
   If chkSchema.checked Then
      xmpResults.InnerHtml = objDataSet.GetXmlSchema() & vbCrlf & vbCrlf
   End If
   If chkXML.checked Then
      xmpResults.InnerHtml += objDataSet.GetXml()
   End If

End Sub
</script>


<!--------------------------------------------------------------------------->
<!-- #include file="..\global\foot.inc" -->
</body>
</html>
